package com.liukai.bishe.presenter.transactionPresenter.impl;

import com.liukai.bishe.model.API;
import com.liukai.bishe.model.doman.transaction.TransactionMessageList;
import com.liukai.bishe.model.doman.transaction.TransactionUseTime;
import com.liukai.bishe.model.doman.transaction.TransactionUserTimeMessageList;
import com.liukai.bishe.presenter.transactionPresenter.ITransactionUserTimePresenter;
import com.liukai.bishe.utils.RetrofitManager;
import com.liukai.bishe.utils.ToastUtil;
import com.liukai.bishe.view.IBaseCallBack;
import com.liukai.bishe.view.ITransactionUserTimeCallBack;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;

public class ITransactionUserTimePresenterImpl implements ITransactionUserTimePresenter {

    private ITransactionUserTimeCallBack mITransactionUserTimeCallBack;

    @Override
    public void findTransactionUserTimeByUserName(String username) {

        Retrofit retrofit = RetrofitManager.getInstance().getRetrofit();
        API api = retrofit.create(API.class);
        Call<List<TransactionUseTime>> task = api.findTransactionUserTimeByUserName(username);
        task.enqueue(new Callback<List<TransactionUseTime>>() {
            @Override
            public void onResponse(Call<List<TransactionUseTime>> call, Response<List<TransactionUseTime>> response) {
                int code = response.code();
                List<TransactionUseTime> transactionUseTimeList = response.body();
                ToastUtil.log("findTransactionUserTimeByUserName","code=============>",code+"");
                mITransactionUserTimeCallBack.findTransactionUserTimeByUserName(transactionUseTimeList);
            }

            @Override
            public void onFailure(Call<List<TransactionUseTime>> call, Throwable t) {
                ToastUtil.log("findTransactionUserTimeByUserName","code=============>",t.toString());
            }
        });


    }

    @Override
    public void registerCallback(IBaseCallBack iBaseCallBack) {

        this.mITransactionUserTimeCallBack = (ITransactionUserTimeCallBack)iBaseCallBack;

    }

    @Override
    public void unregisterCallback(IBaseCallBack iBaseCallBack) {

        if (mITransactionUserTimeCallBack != null) {
            mITransactionUserTimeCallBack = null;
        }

    }
}
